package com.wanczy.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanczy.pojo.RoleTable;
import com.wanczy.service.RoleTableService;
import com.wanczy.service.impl.RoleTableServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@WebServlet("/UpdRoleServlet")
public class UpdRoleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String roleName = request.getParameter("roleName");
		String roleDescribe = request.getParameter("roleDescribe");
		int roleId = Integer.parseInt(request.getParameter("roleId"));
		int roleState = Integer.parseInt(request.getParameter("roleState"));
		RoleTableService service = new RoleTableServiceImpl();
		RoleTable role = new RoleTable(roleId,roleName,roleDescribe,roleState);
		boolean flag = service.doUpd(role);
		JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("flag", flag);
		jsonArray.add(jsonObject);
		out.println(jsonArray.toString());
		out.close();
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
